import { IDomEditor, SlateDescendant, SlateElement } from '@wangeditor/editor';
import { Timeline } from './custom-types';

function parseHtml(
  elem: any,
  children: SlateDescendant[],
  editor: IDomEditor,
): SlateElement {
  const date = elem.getAttribute('data-title') || '';
  return {
    type: 'time-line',
    date,
    children: [{ text: '' }], // void node 必须有一个空白 text
  } as Timeline;
}

const parseHtmlConf = {
  selector: 'div[data-w-e-type="time-line"]',
  parseElemHtml: parseHtml,
};

export default parseHtmlConf;
